package crp.core.security.domain.models;
import io.quarkus.security.runtime.QuarkusPrincipal;

import java.util.Objects;

public class CallerPrincipal extends QuarkusPrincipal {
    public static final String TYPE_SERVER = "SERVER";
    public static final String TYPE_USER = "USER";
    private String type;

    public CallerPrincipal(String name, String type) {
        super(name);
        this.type = type;
    }

    public String getId() {
        return getName();
    }

    public boolean isUser() {
        return isUser(type);
    }

    public boolean isServer() {
        return isServer(type);
    }

    public String getType() {
        return type;
    }

    public static CallerPrincipal fromUser(String id) {
        return new CallerPrincipal(id, TYPE_USER);
    }

    public static CallerPrincipal fromServer(String id) {
        return new CallerPrincipal(id, TYPE_SERVER);
    }

    public static boolean isUser(String type) {
        return Objects.equals(type, TYPE_USER);
    }

    public static boolean isServer(String type) {
        return Objects.equals(type, TYPE_SERVER);
    }
}
